home *** CD-ROM | disk | FTP | other *** search
/ Kellogg's Amérique / Kellogg's Amérique / speed.swf / scripts / fl / managers / StyleManager.as < prev   
Text File  |  2020-08-04  |  8KB  |  257 lines

  1. package fl.managers
  2. {
  3.    import fl.core.UIComponent;
  4.    import flash.text.TextFormat;
  5.    import flash.utils.Dictionary;
  6.    import flash.utils.getDefinitionByName;
  7.    import flash.utils.getQualifiedClassName;
  8.    import flash.utils.getQualifiedSuperclassName;
  9.    
  10.    public class StyleManager
  11.    {
  12.       
  13.       private static var _instance:StyleManager;
  14.        
  15.       
  16.       private var globalStyles:Object;
  17.       
  18.       private var classToDefaultStylesDict:Dictionary;
  19.       
  20.       private var styleToClassesHash:Object;
  21.       
  22.       private var classToStylesDict:Dictionary;
  23.       
  24.       private var classToInstancesDict:Dictionary;
  25.       
  26.       public function StyleManager()
  27.       {
  28.          super();
  29.          styleToClassesHash = {};
  30.          classToInstancesDict = new Dictionary(true);
  31.          classToStylesDict = new Dictionary(true);
  32.          classToDefaultStylesDict = new Dictionary(true);
  33.          globalStyles = UIComponent.getStyleDefinition();
  34.       }
  35.       
  36.       public static function clearComponentStyle(param1:Object, param2:String) : void
  37.       {
  38.          var _loc3_:Class = null;
  39.          var _loc4_:Object = null;
  40.          _loc3_ = getClassDef(param1);
  41.          if((_loc4_ = getInstance().classToStylesDict[_loc3_]) != null && _loc4_[param2] != null)
  42.          {
  43.             delete _loc4_[param2];
  44.             invalidateComponentStyle(_loc3_,param2);
  45.          }
  46.       }
  47.       
  48.       private static function getClassDef(param1:Object) : Class
  49.       {
  50.          var component:Object = param1;
  51.          if(component is Class)
  52.          {
  53.             return component as Class;
  54.          }
  55.          try
  56.          {
  57.             return getDefinitionByName(getQualifiedClassName(component)) as Class;
  58.          }
  59.          catch(e:Error)
  60.          {
  61.             if(component is UIComponent)
  62.             {
  63.                try
  64.                {
  65.                   return component.loaderInfo.applicationDomain.getDefinition(getQualifiedClassName(component)) as Class;
  66.                }
  67.                catch(e:Error)
  68.                {
  69.                }
  70.             }
  71.             return null;
  72.          }
  73.       }
  74.       
  75.       public static function clearStyle(param1:String) : void
  76.       {
  77.          setStyle(param1,null);
  78.       }
  79.       
  80.       public static function setComponentStyle(param1:Object, param2:String, param3:Object) : void
  81.       {
  82.          var _loc4_:Class = null;
  83.          var _loc5_:Object = null;
  84.          _loc4_ = getClassDef(param1);
  85.          if((_loc5_ = getInstance().classToStylesDict[_loc4_]) == null)
  86.          {
  87.             _loc5_ = getInstance().classToStylesDict[_loc4_] = {};
  88.          }
  89.          if(_loc5_ == param3)
  90.          {
  91.             return;
  92.          }
  93.          _loc5_[param2] = param3;
  94.          invalidateComponentStyle(_loc4_,param2);
  95.       }
  96.       
  97.       private static function setSharedStyles(param1:UIComponent) : void
  98.       {
  99.          var _loc2_:StyleManager = null;
  100.          var _loc3_:Class = null;
  101.          var _loc4_:Object = null;
  102.          var _loc5_:* = null;
  103.          _loc2_ = getInstance();
  104.          _loc3_ = getClassDef(param1);
  105.          _loc4_ = _loc2_.classToDefaultStylesDict[_loc3_];
  106.          for(_loc5_ in _loc4_)
  107.          {
  108.             param1.setSharedStyle(_loc5_,getSharedStyle(param1,_loc5_));
  109.          }
  110.       }
  111.       
  112.       public static function getComponentStyle(param1:Object, param2:String) : Object
  113.       {
  114.          var _loc3_:Class = null;
  115.          var _loc4_:Object = null;
  116.          _loc3_ = getClassDef(param1);
  117.          return (_loc4_ = getInstance().classToStylesDict[_loc3_]) == null ? null : _loc4_[param2];
  118.       }
  119.       
  120.       private static function getInstance() : *
  121.       {
  122.          if(_instance == null)
  123.          {
  124.             _instance = new StyleManager();
  125.          }
  126.          return _instance;
  127.       }
  128.       
  129.       private static function invalidateComponentStyle(param1:Class, param2:String) : void
  130.       {
  131.          var _loc3_:Dictionary = null;
  132.          var _loc4_:* = null;
  133.          var _loc5_:UIComponent = null;
  134.          _loc3_ = getInstance().classToInstancesDict[param1];
  135.          if(_loc3_ == null)
  136.          {
  137.             return;
  138.          }
  139.          for(_loc4_ in _loc3_)
  140.          {
  141.             if((_loc5_ = _loc4_ as UIComponent) != null)
  142.             {
  143.                _loc5_.setSharedStyle(param2,getSharedStyle(_loc5_,param2));
  144.             }
  145.          }
  146.       }
  147.       
  148.       private static function invalidateStyle(param1:String) : void
  149.       {
  150.          var _loc2_:Dictionary = null;
  151.          var _loc3_:* = null;
  152.          _loc2_ = getInstance().styleToClassesHash[param1];
  153.          if(_loc2_ == null)
  154.          {
  155.             return;
  156.          }
  157.          for(_loc3_ in _loc2_)
  158.          {
  159.             invalidateComponentStyle(Class(_loc3_),param1);
  160.          }
  161.       }
  162.       
  163.       public static function registerInstance(param1:UIComponent) : void
  164.       {
  165.          var inst:StyleManager = null;
  166.          var classDef:Class = null;
  167.          var target:Class = null;
  168.          var defaultStyles:Object = null;
  169.          var styleToClasses:Object = null;
  170.          var n:String = null;
  171.          var instance:UIComponent = param1;
  172.          inst = getInstance();
  173.          classDef = getClassDef(instance);
  174.          if(classDef == null)
  175.          {
  176.             return;
  177.          }
  178.          if(inst.classToInstancesDict[classDef] == null)
  179.          {
  180.             inst.classToInstancesDict[classDef] = new Dictionary(true);
  181.             target = classDef;
  182.             while(defaultStyles == null)
  183.             {
  184.                if(target["getStyleDefinition"] != null)
  185.                {
  186.                   defaultStyles = target["getStyleDefinition"]();
  187.                   break;
  188.                }
  189.                try
  190.                {
  191.                   target = instance.loaderInfo.applicationDomain.getDefinition(getQualifiedSuperclassName(target)) as Class;
  192.                }
  193.                catch(err:Error)
  194.                {
  195.                   try
  196.                   {
  197.                      target = getDefinitionByName(getQualifiedSuperclassName(target)) as Class;
  198.                   }
  199.                   catch(e:Error)
  200.                   {
  201.                      defaultStyles = UIComponent.getStyleDefinition();
  202.                      break;
  203.                   }
  204.                }
  205.             }
  206.             styleToClasses = inst.styleToClassesHash;
  207.             for(n in defaultStyles)
  208.             {
  209.                if(styleToClasses[n] == null)
  210.                {
  211.                   styleToClasses[n] = new Dictionary(true);
  212.                }
  213.                styleToClasses[n][classDef] = true;
  214.             }
  215.             inst.classToDefaultStylesDict[classDef] = defaultStyles;
  216.             inst.classToStylesDict[classDef] = {};
  217.          }
  218.          inst.classToInstancesDict[classDef][instance] = true;
  219.          setSharedStyles(instance);
  220.       }
  221.       
  222.       public static function getStyle(param1:String) : Object
  223.       {
  224.          return getInstance().globalStyles[param1];
  225.       }
  226.       
  227.       private static function getSharedStyle(param1:UIComponent, param2:String) : Object
  228.       {
  229.          var _loc3_:Class = null;
  230.          var _loc4_:StyleManager = null;
  231.          var _loc5_:Object = null;
  232.          _loc3_ = getClassDef(param1);
  233.          if((_loc5_ = (_loc4_ = getInstance()).classToStylesDict[_loc3_][param2]) != null)
  234.          {
  235.             return _loc5_;
  236.          }
  237.          if((_loc5_ = _loc4_.globalStyles[param2]) != null)
  238.          {
  239.             return _loc5_;
  240.          }
  241.          return _loc4_.classToDefaultStylesDict[_loc3_][param2];
  242.       }
  243.       
  244.       public static function setStyle(param1:String, param2:Object) : void
  245.       {
  246.          var _loc3_:Object = null;
  247.          _loc3_ = getInstance().globalStyles;
  248.          if(_loc3_[param1] === param2 && !(param2 is TextFormat))
  249.          {
  250.             return;
  251.          }
  252.          _loc3_[param1] = param2;
  253.          invalidateStyle(param1);
  254.       }
  255.    }
  256. }
  257.